/* eslint-disable */
// @ts-nocheck
import axios from 'axios';

const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:8000';

// 创建axios实例
const api = axios.create({
  baseURL: API_BASE_URL,
  headers: {
    'Content-Type': 'application/json',
  },
});

// 请求拦截器
api.interceptors.request.use(
  (config) => {
    // 可以在这里添加认证头或其他请求配置
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

// 响应拦截器
api.interceptors.response.use(
  (response) => response,
  (error) => {
    console.error('API请求错误:', error);
    return Promise.reject(error);
  }
);

// API响应类型定义
export interface ApiResponse<T> {
  data: T;
  message?: string;
}

// Example 相关类型定义
export interface Example {
  id: number;
  name: string;
  description?: string;
  is_active: boolean;
  created_at: string;
  updated_at?: string;
}

export interface ExampleCreate {
  name: string;
  description?: string;
}

export interface ExampleUpdate {
  name?: string;
  description?: string;
}

// 基础API函数
export const basicAPI = {
  // 获取Hello消息
  getHello: async (): Promise<{message: string}> => {
    const response = await api.get('/api/hello');
    return response.data;
  },

  // 健康检查
  healthCheck: async (): Promise<{message: string, status: string, version: string}> => {
    const response = await api.get('/');
    return response.data;
  },
};

// Examples API
export const examplesAPI = {
  // 获取所有示例
  getExamples: async (skip: number = 0, limit: number = 100): Promise<Example[]> => {
    const response = await api.get(`/api/examples/?skip=${skip}&limit=${limit}`);
    return response.data;
  },

  // 获取示例总数
  getExamplesCount: async (): Promise<{count: number}> => {
    const response = await api.get('/api/examples/count');
    return response.data;
  },

  // 根据ID获取示例
  getExample: async (id: number): Promise<Example> => {
    const response = await api.get(`/api/examples/${id}`);
    return response.data;
  },

  // 创建示例
  createExample: async (data: ExampleCreate): Promise<Example> => {
    const response = await api.post('/api/examples/', data);
    return response.data;
  },

  // 更新示例
  updateExample: async (id: number, data: ExampleUpdate): Promise<Example> => {
    const response = await api.put(`/api/examples/${id}`, data);
    return response.data;
  },

  // 删除示例
  deleteExample: async (id: number): Promise<{message: string}> => {
    const response = await api.delete(`/api/examples/${id}`);
    return response.data;
  },
};

export default api; 